package normal.test;

/**
 * @author futao
 * Created on 2017/11/29 - 14:53.
 */
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.util.Map;
public class AA {
    public static void main(String[] args) {
        String jsonData ="{'a':1,'b':2,'c':3}";
        System.out.println(jsonData);

        Map<String,String> map = parseData(jsonData);
        System.out.println(map.get("a"));
        for (String key : map.keySet()) {
            System.out.println("key:" + key + " values:" + map.get(key));
        }
    }

    /**
     *
     * 函数名称: parseData
     * 函数描述: 将json字符串转换为map
     * @param data
     * @return
     */
    private static Map<String, String> parseData(String data){
        GsonBuilder gb = new GsonBuilder();
        Gson g = gb.create();
        Map<String, String> map = g.fromJson(data, new TypeToken<Map<String, String>>() {}.getType());
        return map;
    }

}